<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8" import="java.util.List"%>
<script type="text/javascript" charset="UTF-8">
	var contactId="${param.contactId}";
	var refObject=2;
	var meetingId="";
 
	var dg3;
	var d3;
	var f3;
	
	var dg4;
	var d4;
	var f4;
	$(function() {
		
		f3 = $('#f3').form();
		
		d3 = $('#d3').show().dialog({
			modal : true,
			title : '会议',
			buttons : [ {
				text : '确定',
				handler : function() {
					var formData=f3.form("serialize");
					formData.contact_id=contactId;
					var data=JSON.stringify(formData);
					$("#f3 input[name=data]").val(data);
					if (f3.find('[name=meeting_id]').val() != '') {
						f3.form('submit', {
							url : '<%=request.getContextPath()%>/demand/meeting/save.htm',
							success : function(data) {
								d3.dialog('close');
								$.messager.show({
									msg : '编辑成功！',
									title : '提示'
								});
								dg3.datagrid('reload');
							}
						});
					} else {
						f3.form('submit', {
					        url : '<%=request.getContextPath()%>/demand/meeting/save.htm',
							success : function(v) {
								try {
									 
									d3.dialog('close');
									$.messager.show({
										msg : '创建成功！',
										title : '提示'
									});
									dg3.datagrid('reload');
								} catch (e) {
									$.messager.show({
										msg : '操作失败！',
										title : '提示'
									});
								}
							}
						});
					}
				}
			} ]
		}).dialog('close');
		
		dg3 = $('#dg3').datagrid({
			url : '<%=request.getContextPath()%>/demand/meeting/list.htm?contactId=${param.contactId}',
			toolbar : '#toolbar3',
			title : '会议',
			iconCls : 'icon-save',
			pagination : true,
			pageSize : 5,
			pageList : [5],
			//fit : true,
			fitColumns : true,
			nowrap : false,
			border : true,
			selectOnCheck:false,
			checkOnSelect:false,
			singleSelect:true,
			idField : 'meeting_id',
			frozenColumns : [ [ {
				field : 'meeting_id',
				width : 50,
				checkbox : true
			}] ],
			columns : [ [ 
			{
				field : 'meeting_name',
				title : '会议名称',
				width : 150
			},
			{
				field : 'meeting_type_',
				title : '会议类型',
				width : 100
			},
			{
				field : 'meeting_date',
				title : '会议时间',
				width : 100
			},
			{
				field : 'creator_',
				title : '创建人',
				width : 100
			},
			
			{
				field : 'meeting_desc',
				title : '会议描述',
				width : 250
			},
			{
				field : 'meeting_person',
				title : '参会人员',
				width : 150
			},
			{
				field : 'state_date',
				title : '更新时间',
				width : 100
			},{
				field : 'creator',
				hidden : true
			}
			] ],
			onClickCell: function(index,field,value){
				var rows = dg3.datagrid('getRows');
				meetingId= rows[index].meeting_id;
				dg4.datagrid('load', {
					relId : rows[index].meeting_id,
					refObject:refObject
				});
				dg4.datagrid({
						title:"【"+rows[index].meeting_name+"】任务关联文档"
						});
			}
		});
		
		f4 = $('#f4').form();
		 
		d4 = $('#d4').show().dialog({
			modal : true,
			title : (refObject==1?'任务':'会议')+'文档',
			buttons : [ {
				text : '确定',
				handler : function() {
					var formData=f4.form("serialize");
					formData.ref_object=refObject;
					formData.ref_id=meetingId;
					var data=JSON.stringify(formData);
					$("#f4 input[name=data]").val(data);
					if (f4.find('[name=doc_id]').val() != '') {
						f4.form('submit', {
							url : '<%=request.getContextPath()%>/demand/doc/save.htm',
							success : function(data) {
								d4.dialog('close');
								$.messager.show({
									msg : '编辑成功！',
									title : '提示'
								});
								dg4.datagrid('reload');
							}
						});
					} else {
						f4.form('submit', {
							url : '<%=request.getContextPath()%>/demand/doc/save.htm',
							success : function(v) {
								try {
						 
									d4.dialog('close');
									$.messager.show({
										msg : '创建成功！',
										title : '提示'
									});
									dg4.datagrid('reload');
								 
								} catch (e) {
									$.messager.show({
										msg : '操作失败！',
										title : '提示'
									});
								}
							}
						});
					}
				}
			} ]
		}).dialog('close');

		dg4 = $('#dg4').datagrid({
			url : '<%=request.getContextPath()%>/demand/doc/list.htm',
			toolbar : '#toolbar4',
			title : (refObject==1?'任务':'会议')+'文档',
			iconCls : 'icon-save',
			pagination : true,
			pageSize : 5,
			pageList : [5],
			//fit : true,
			//fitColumns : true,
			nowrap : false,
			border : true,
			idField : 'doc_id',
			frozenColumns : [ [ {
				field : 'doc_id',
				width : 50,
				checkbox : true
			},
			{
				field : 'doc_type_',
				title : '文档类型',
				width : 80
			},
			{
				field : 'create_date',
				title : '文档创建时间',
				width : 100
			}] ],
			columns : [ [ 			
			{
				field : 'doc_author_',
				title : '创建人',
				width : 100
			},
			{
				field : 'doc_maintain',
				title : '维护人',
				width : 100
			},
			{
				field : 'doc_path',
				title : '文档路径',
				width : 300
			},
			{
				field : 'doc_desc',
				title : '文档描述',
				width : 300
			}
			]],
			onDblClickCell: function(index,field,value){
				var rows = dg4.datagrid('getRows');
				d4.dialog('open');
				f4.form('clear');
				f4.form('load','<%=request.getContextPath()%>/demand/doc/get.htm?id='+rows[index].doc_id);
				
			}
		});

	});

	function append3() {
		d3.dialog('open');
		f3.form('clear');
	}
	function append4() {
		if(meetingId==""){
			$.messager.show({
				msg : '请先双击选择一条任务，再新建文档',
				title : '提示'
			});
			return false;
		}
		d4.dialog('open');
		f4.form('clear');
	}

	function edit3() {
		var rows = dg3.datagrid('getSelections');
		if (rows.length != 1 && rows.length != 0) {
			var names = [];
			for ( var i = 0; i < rows.length; i++) {
				names.push(rows[i].name);
			}
			$.messager.show({
				msg : '只能择一个记录编辑！您已经选择了【' + names.join(',') + '】' + rows.length + '条',
				title : '提示'
			});
		} else if (rows.length == 1) {
			if(rows[0].creator!='${userRoleInfo.ur_id}'){
				$.messager.show({
					msg : '请对自己创建的会议进行操作',
					title : '提示'
				});
			}else{
				d3.dialog('open');
				f3.form('clear');
				f3.form('load','<%=request.getContextPath()%>/demand/meeting/get.htm?id='+rows[0].meeting_id);
			}
			
		}else{
			$.messager.show({
				msg : '请选择一条记录进行操作',
				title : '提示'
			});
		}
	}
	function edit4() {
		var rows = dg4.datagrid('getSelections');
		if (rows.length != 1 && rows.length != 0) {
			var names = [];
			for ( var i = 0; i < rows.length; i++) {
				names.push(rows[i].name);
			}
			$.messager.show({
				msg : '只能择一个记录编辑！您已经选择了【' + names.join(',') + '】' + rows.length + '条',
				title : '提示'
			});
		} else if (rows.length == 1) {
			d4.dialog('open');
			f4.form('clear');
			f4.form('load','<%=request.getContextPath()%>/demand/doc/get.htm?id='+rows[0].doc_id);
		}else{
			$.messager.show({
				msg : '请选择一条记录进行操作',
				title : '提示'
			});
		}
	}
	
	function remove3() {
		var ids = [];
		var rows = dg3.datagrid('getSelections');
		if (rows.length > 0) {
			$.messager.confirm('请确认', '您要删除当前所选项目？', function(r) {
				if (r) {
					for ( var i = 0; i < rows.length; i++) {
						ids.push(rows[i].meeting_id);
					}
					$.ajax({
						url : '<%=request.getContextPath()%>/demand/meeting/del.htm',
						data : {
							id : ids.join(',')
						},
						cache : false,
						success : function(response) {
							dg3.datagrid('unselectAll');
							dg3.datagrid('reload');
							$.messager.show({
								title : '提示',
								msg : '删除成功！'
							});
						}
					});
				}
			});
		} else {
			$.messager.alert('提示', '请选择要删除的记录！', 'error');
		}
	}
	
	function remove4() {
		var ids = [];
		var rows = dg4.datagrid('getSelections');
		if (rows.length > 0) {
			$.messager.confirm('请确认', '您要删除当前所选项目？', function(r) {
				if (r) {
					for ( var i = 0; i < rows.length; i++) {
						ids.push(rows[i].doc_id);
					}
					$.ajax({
						url : '<%=request.getContextPath()%>/demand/doc/del.htm',
						data : {
							id : ids.join(',')
						},
						cache : false,
						success : function(response) {
							dg4.datagrid('unselectAll');
							dg4.datagrid('reload');
							$.messager.show({
								title : '提示',
								msg : '删除成功！'
							});
						}
					});
				}
			});
		} else {
			$.messager.alert('提示', '请选择要删除的记录！', 'error');
		}
	}

	 
	function clearFun() {
		$('#toolbar input').val('');
		dg3.datagrid('load', {});
	}
	function clearFun2() {
		$('#toolbar input').val('');
		dg4.datagrid('load', {});
	}
</script>
	
	<%-- 会议  --%>
	<div region="center" border="false" style="overflow: hidden;">
		<div id="toolbar3" class="datagrid-toolbar" style="height: auto;">
			<div>
				<a class="easyui-linkbutton" iconCls="icon-add" onclick="append3();" plain="true" href="javascript:void(0);">增加</a>
				<a class="easyui-linkbutton"  ${userRoleInfo.role_id!='1'?"disabled='true'":""}  iconCls="icon-remove" onclick="remove3();" plain="true" href="javascript:void(0);">删除</a> 
				<a class="easyui-linkbutton" iconCls="icon-edit" onclick="edit3();" plain="true" href="javascript:void(0);">编辑</a>
				<a class="easyui-linkbutton" iconCls="icon-undo" onclick="dg3.datagrid('unselectAll');" plain="true" href="javascript:void(0);">取消选中</a>
			</div>
		</div>
		<table id="dg3"></table>
	</div>
   
	<%-- 会议 --%>
	<br/>
	<%-- 文档  --%>
	<div region="center" border="false" style="overflow: hidden;">
		<div id="toolbar4" class="datagrid-toolbar" style="height: auto;">
			<div>
				<a class="easyui-linkbutton" iconCls="icon-add" onclick="append4();" plain="true" href="javascript:void(0);">增加</a>
				<a class="easyui-linkbutton" ${userRoleInfo.role_id!='1'?"disabled='true'":""}  iconCls="icon-remove" onclick="remove4();" plain="true" href="javascript:void(0);">删除</a> 
				<a class="easyui-linkbutton" iconCls="icon-edit" onclick="edit4();" plain="true" href="javascript:void(0);">编辑</a>
				<a class="easyui-linkbutton" iconCls="icon-undo" onclick="dg4.datagrid('unselectAll');" plain="true" href="javascript:void(0);">取消选中</a>
			</div>
		</div>
		<table id="dg4"></table>
	</div>
	
	<%-- 文档  --%>